/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.ArrayList;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Nordinator
 */
@Entity
@Table(name="LISTELECTURE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ListeLecture.findAll", query = "SELECT l FROM ListeLecture l"),
    @NamedQuery(name = "ListeLecture.findById", query = "SELECT l FROM ListeLecture l where l.id = :id"),
    @NamedQuery(name = "ListeLecture.dropById", query = "DELETE FROM ListeLecture l where l.id = :id")})
public class ListeLecture implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    //N.B: la liste de lecture n'est initialisé que si le 2e constructeur est utilisé
    private ArrayList<Long> liste;
    
    public ListeLecture(){
        
    }
    
    public ListeLecture(String nom){
        this.name = nom;
        liste = new ArrayList<Long>();
    }
    
    public void setListe(ArrayList<Long> array){
        liste = array;
    }
    
    public ArrayList<Long> getListe(){
        return liste;
    }
    
    public void addSong(Long songId){
        liste.add(songId);
    }
    
    /**
     * Permute la position entre la chanson i et j
     */
    public void permutSong(int i, int j){
        try{
            Long tmpId = liste.get(i);
            if(!liste.isEmpty()){
                liste.set(i, liste.get(j));
                liste.set(j, tmpId);
            }
        }catch(ArrayIndexOutOfBoundsException e){
            System.out.println("ListeLecture.permutSong : Index non respecté !");
        }
    }
    /**
     * Get the value of name
     *
     * @return the value of name
     */
    public String getName() {
        return name;
    }

    /**
     * Set the value of name
     *
     * @param name new value of name
     */
    public void setName(String name) {
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ListeLecture)) {
            return false;
        }
        ListeLecture other = (ListeLecture) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.ListeLecture[ id=" + id + " ]";
    }
}
